package role

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/role/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) AssignPermission(ctx context.Context, req *v1.AssignPermissionReq) (res *v1.AssignPermissionRes, err error) {
	// tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)
	// if len(req.PermissionsId) == 0 {
	// 	return nil, gerror.NewCode(consts.MustSelectAtLeastOnePermission)
	// }
	in := &v1.AssignPermissionInput{
		// TenantCode:    tenantCode,
		Id:            req.Id,
		MenuId:        req.MenuId,
		Include:       req.Include,
		PermissionsId: req.PermissionsId,
	}
	out := &v1.AssignPermissionOutput{}
	out, err = service.Role().AssignPermission(ctx, in)
	if err != nil {
		return nil, err
	}
	return &v1.AssignPermissionRes{Rows: out.Rows}, nil

}
